import { Loading } from 'element-ui'

/**
 *  loading控制
 */
export default {
  num: 0,
  show() {
    this.num += 1
    if (this.num === 1) {
      Loading.service({
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.1)'
      }) // 显示loading
    }
  },
  hide() {
    // 等待发出去的请求返回结果后结束loading
    if (this.num > 0) this.num -= 1
    if (this.num === 0) {
      Loading.service().close() // 结束loading
    }
  }
}
